
define([
    "jquery",
    "IO",
    "UPLOADUI",
    "UPLOAD",
    "jqueryUI",
    "bootbox",
    //"text!/js/biz/keb/activity/definebt.html"
], function ($, IO, upui, up, jui, bootbox, definebt) {
    var type;
    $(function () {
        var grid;
        //每列数据列性
        var columns = [
            {
                title: '题目',
                dataIndex: 'question',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].title + "</span>";
                }
            },
            {
                title: '操作',
                dataIndex: 'action',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><a href='javascript:void(0)' style='color: deepskyblue;' class='add' act_id='"+data[datarow].question_id
                        +"'>更换题目</a></span>";
                }
            },

        ];


        //数组初始化

        function dataInit() {
            var course_id = $("#course_id").val();
            type = $("#category option:selected").val();
            if(type == '判断')
                type = 0 ;
            else if (type == '单选')
                type = 1;
            else if  (type == '多选')
                type = 2;
            else
                type = '';
            grid = new Grid("/pte/api/addtime-test?course_id="+course_id+"&type="+type, $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {

            var content=$("#citiao_content").val();
            var param="content=" +content;
            return param;
        }
        dataInit();
        //查询
        $("#query").bind("click", function () {
            dataInit();
        });
        $("#category").on("change",function(){
            console.log($(this).val())
            dataInit();
        })
    });
//修改时间
    $(document).on("click",".publish",function(){
        var course_id = $("#course_id").val();
        var lecture_id = $("#lecture_id").val();
        var joint_id = $("#joint_id").val();
        var question_id = $("#question_id").val();
        var min = parseInt($("#min").val());
        var sec = parseInt($("#sec").val());
        var time = min*60+sec;
        var param = {course_id:course_id,lecture_id:lecture_id,joint_id:joint_id,time:time,question_id:question_id};
        bootbox.confirm("确定要更改为该时间吗？",function(result){
            if(result) {
                IO.post("/pte/api/timecourse_test_update",param,function(d){
                    bootbox.alert(d.msg,function(){
                        if (d.code == 0) {
                            location.href = '/pte/course-test?course_id='+course_id+'&lecture_id='+lecture_id;
                        }
                    })
                });
            }
        });
    });

//选择题目
    $(document).on("click",".add",function(){
        var category=$("#category option:selected").val();
        var act_id=$(this).attr("act_id");
        var min = parseInt($("#min").val());
        var sec = parseInt($("#sec").val());
        var time = min*60+sec;
        var course_id = $("#course_id").val();
        var lecture_id = $("#lecture_id").val();
        var joint_id = $("#joint_id").val();
        var param = {course_id:course_id,lecture_id:lecture_id,joint_id:joint_id,time:time,question_id:act_id};
        //console.log('我的参数',param);
        //console.log('哈哈',category);
        if (category=='请选择题型') {
            alert("请选择题型");
            return;
        }
        if (isNaN(min)){
            alert("请输入正确的时间");
            return;
        }
        if (isNaN(sec)){
            alert("请输入正确的时间");
            return;
        }
        bootbox.confirm("确定要更改为该题目吗？",function(result){
            if(result) {
                IO.post("/pte/api/timecourse_test_update",param,function(d){
                    bootbox.alert(d.msg,function(){
                        if (d.code == 0) {
                            location.href = '/pte/course-test?course_id='+course_id+'&lecture_id='+lecture_id;
                        }
                    })
                });
            }
        });

    });
});